package com.example.algorithm.tree;

/**
 * @author : zhy
 * @since : 2022/8/10
 * 验证二叉搜索树
 */
public class CheckSearchTree {
    TreeNode max;
    public boolean isValidBST(TreeNode root) {
        if(root==null){
            return true;
        }
        boolean left=isValidBST(root.left);
        if(!left){
            return false;
        }
        if(max!=null&&root.val<= max.val){
            return false;
        }
        max=root;
        boolean right=isValidBST(root.right);
        return right;
    }
}
